package com.prp.db.daoimpl.mysql;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

import com.prp.db.idao.IArtificialSubjectRecommendationRecordDAO;
import com.prp.db.po.ArtificialSubjectRecommendationRecord;

/**
 * A data access object (DAO) providing persistence and search support for
 * ArtificialSubjectRecommendationRecord entities. Transaction control of the
 * save(), update() and delete() operations can directly support Spring
 * container-managed transactions or they can be augmented to handle
 * user-managed Spring transactions. Each of these methods provides additional
 * information for how to configure it for the desired type of transaction
 * control.
 * 
 * @see com.prp.db.daoimpl.mysql.ArtificialSubjectRecommendationRecord
 * @author MyEclipse Persistence Tools
 */

public class ArtificialSubjectRecommendationRecordDAO extends BaseHibernateDAO implements IArtificialSubjectRecommendationRecordDAO{
	private static final Log log = LogFactory
			.getLog(ArtificialSubjectRecommendationRecordDAO.class);
	// property constants
	public static final String RECOMM_FROM_ID = "recommFromId";
	public static final String RECOMM_TO_ID = "recommToId";
	public static final String REOMM_ARTICLE_ID = "reommArticleId";

	public void save(ArtificialSubjectRecommendationRecord transientInstance) {
		log.debug("saving ArtificialSubjectRecommendationRecord instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(ArtificialSubjectRecommendationRecord persistentInstance) {
		log.debug("deleting ArtificialSubjectRecommendationRecord instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public ArtificialSubjectRecommendationRecord findById(java.lang.Integer id) {
		log
				.debug("getting ArtificialSubjectRecommendationRecord instance with id: "
						+ id);
		try {
			ArtificialSubjectRecommendationRecord instance = (ArtificialSubjectRecommendationRecord) getSession()
					.get(
							"com.prp.db.daoimpl.mysql.ArtificialSubjectRecommendationRecord",
							id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(ArtificialSubjectRecommendationRecord instance) {
		log
				.debug("finding ArtificialSubjectRecommendationRecord instance by example");
		try {
			List results = getSession()
					.createCriteria(
							"com.prp.db.daoimpl.mysql.ArtificialSubjectRecommendationRecord")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log
				.debug("finding ArtificialSubjectRecommendationRecord instance with property: "
						+ propertyName + ", value: " + value);
		try {
			String queryString = "from ArtificialSubjectRecommendationRecord as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByRecommFromId(Object recommFromId) {
		return findByProperty(RECOMM_FROM_ID, recommFromId);
	}

	public List findByRecommToId(Object recommToId) {
		return findByProperty(RECOMM_TO_ID, recommToId);
	}

	public List findByReommArticleId(Object reommArticleId) {
		return findByProperty(REOMM_ARTICLE_ID, reommArticleId);
	}

	public List findAll() {
		log
				.debug("finding all ArtificialSubjectRecommendationRecord instances");
		try {
			String queryString = "from ArtificialSubjectRecommendationRecord";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public ArtificialSubjectRecommendationRecord merge(
			ArtificialSubjectRecommendationRecord detachedInstance) {
		log.debug("merging ArtificialSubjectRecommendationRecord instance");
		try {
			ArtificialSubjectRecommendationRecord result = (ArtificialSubjectRecommendationRecord) getSession()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(ArtificialSubjectRecommendationRecord instance) {
		log
				.debug("attaching dirty ArtificialSubjectRecommendationRecord instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(ArtificialSubjectRecommendationRecord instance) {
		log
				.debug("attaching clean ArtificialSubjectRecommendationRecord instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}